<template>
  <div class="game-management">
    <h1 class="title">游戏管理页面</h1>
    <div class="game-list">
      <GameCard 
        v-for="game in games" 
        :key="game.id" 
        :title="game.title"
        :description="game.description"
        :image="game.image"
        :link="game.link"
        :customAction="game.customAction"
      />
    </div>
    
    <!-- 贪吃蛇游戏弹窗 -->
    <div v-if="showSnakeGame" class="game-modal-overlay">
      <div class="game-modal">
        <button @click="closeSnakeGame" class="close-button">×</button>
        <SnakeGame />
      </div>
    </div>
    
    <!-- 网格染色挑战弹窗 -->
    <div v-if="showColorChallenge" class="game-modal-overlay">
      <div class="game-modal">
        <button @click="closeColorChallenge" class="close-button">×</button>
        <ColorChallenge />
      </div>
    </div>
    
    <!-- 华容道游戏弹窗 -->
    <div v-if="showHuarongdaoGame" class="game-modal-overlay">
      <div class="game-modal">
        <button @click="closeHuarongdaoGame" class="close-button">×</button>
        <HuarongdaoGame />
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import GameCard from './GameCard.vue'
import SnakeGame from './SnakeGame.vue'
import ColorChallenge from './ColorChallenge.vue'
import HuarongdaoGame from './HuarongdaoGame.vue'

// 游戏列表
defineOptions({
  name: 'GameManagement'
});

// 控制是否显示游戏组件
const showSnakeGame = ref(false);
const showColorChallenge = ref(false);
const showHuarongdaoGame = ref(false);

// 打开贪吃蛇游戏
function openSnakeGame() {
  showSnakeGame.value = true;
}

// 关闭贪吃蛇游戏
function closeSnakeGame() {
  showSnakeGame.value = false;
}

// 打开网格染色挑战
function openColorChallenge() {
  showColorChallenge.value = true;
}

// 关闭网格染色挑战
function closeColorChallenge() {
  showColorChallenge.value = false;
}

// 打开华容道游戏
function openHuarongdaoGame() {
  showHuarongdaoGame.value = true;
}

// 关闭华容道游戏
function closeHuarongdaoGame() {
  showHuarongdaoGame.value = false;
}

const games = ref([
  {
    id: 1,
    title: '贪吃蛇游戏',
    description: '经典的贪吃蛇游戏，通过方向键控制蛇的移动，吃到食物增长长度。',
    image: '/images/snake-game.png',
    customAction: openSnakeGame
  },
  {
    id: 2,
    title: '网格染色挑战',
    description: '通过有限的步数，将整个网格染成目标颜色的挑战游戏。',
    image: '/images/color-challenge.png',
    customAction: openColorChallenge
  },
  {    id: 3,
    title: '华容道解谜',
    description: '经典的华容道解谜游戏，通过移动方块让曹操从出口逃脱。',
    image: '/images/puzzle-game.png',
    customAction: openHuarongdaoGame
  }
])
</script>

<style scoped>
.game-management {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  font-family: 'Arial', sans-serif;
}

.title {
  font-size: 2.5rem;
  margin-bottom: 30px;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
  animation: fadeIn 1s ease-in-out;
}

.game-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
  width: 100%;
  max-width: 1200px;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 游戏弹窗样式 */
.game-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  overflow-y: auto;
}

.game-modal {
  background-color: white;
  border-radius: 12px;
  max-width: 100%;
  max-height: 90vh;
  overflow: hidden;
  position: relative;
  box-shadow: 0 10px 50px rgba(0, 0, 0, 0.3);
}

.close-button {
  position: absolute;
  top: 15px;
  right: 15px;
  width: 40px;
  height: 40px;
  border: none;
  background-color: rgba(255, 255, 255, 0.9);
  border-radius: 50%;
  font-size: 24px;
  cursor: pointer;
  z-index: 10;
  transition: all 0.3s ease;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.close-button:hover {
  background-color: #e74c3c;
  color: white;
  transform: scale(1.1);
}

/* 响应式调整 */
@media (max-width: 768px) {
  .game-modal {
    width: 95vw;
    max-height: 95vh;
  }
  
  .close-button {
    top: 10px;
    right: 10px;
    width: 35px;
    height: 35px;
    font-size: 20px;
  }
}
</style>